import Vue from 'vue'
import Vuex from 'vuex'
import {getUserInfo} from "../api/api";
// import moudelA from "./course";


Vue.use(Vuex)

export default new Vuex.Store({
  //全局状态  初始值
  state: {
    isLogin:false,
    userInfo:{},
    visible:false,
    visibleGet:false
  },
  mutations:{
    changeIsLogin(state,payload){
      state.isLogin = payload.isLogin
      console.log(payload.isLogin)
      console.log(state.isLogin)

    },
    // 参数一：就是全局状态state 参数二  就是调用方法时的传参
    changeLogin(state,payload){
      state.userInfo  = payload.userInfo
      console.log(payload)
      state.isLogin = true
      state.userInfo  = payload.userInfo
      console.log(state.userInfo)
    },
    changeVisible(state,payload){
      state.visible = payload
    },
    changeVisibleGet(state,payload){
      state.visibleGet = payload
    }
  },
  //判断是否登录
  actions:{
    asyncChangeLogin(context){
      //
      getUserInfo().then(res=>{
        console.log(res)
        if(res.data.code ==0){

          context.commit("changeLogin",res.data)
        }
      })
    }
  }

})
